<?php
class Instituciones_Form_Instalaciones extends Form_Cna {

    public function __construct($options = null) {
        parent::__construct($options);
    }

    public function init() {
        $domConfig = Zend_Registry::get('domConfig'); //esto se crea en el bootstrap
        $this->setName('instalaciones');
        $this->setMethod("post");
        $this->setAttrib('enctype', 'multipart/form-data');
        $codtab = new Zend_Form_Element_Hidden("codtab");
        $codboton = new Zend_Form_Element_Hidden("codboton");
        $codboton2 = new Zend_Form_Element_Hidden("codboton2");
        $array_elements[] = $codtab;
        $array_elements[] = $codboton;
        $array_elements[] = $codboton2;
        $array_instalaciones = $domConfig->INSTALACION_FISICA->toArray();
        $array_tenencia = $domConfig->TENENCIA->toArray();
        
        //Instalaciones físicas
        foreach($array_instalaciones as $keyi => $valuei) {
            foreach($array_tenencia as $keyt => $valuet) {
                $element = new Zend_Form_Element_Text("cantidad_{$keyi}_{$keyt}");
                $element->addFilter('StripTags');
                $element->addFilter('StringTrim');
                $element->addValidator('digits');
                $element->setAttrib("size", 7);
                $array_elements[] = $element;
                $element = new Zend_Form_Element_Text("area_{$keyi}_{$keyt}");
                $element->addFilter('StripTags');
                $element->addFilter('StringTrim');
                $element->addValidator('digits');
                $element->setAttrib("size", 7);
                $array_elements[] = $element;
            }
            $element = new Zend_Form_Element_Text("sumac_{$keyi}");
            $element->helper = "formNote";
            $element->setAttrib("readonly", "readonly");
            $element->setAttrib("size", 7);
            $array_elements[] = $element;
            $element = new Zend_Form_Element_Text("sumaa_{$keyi}");
            $element->helper = "formNote";
            $element->setAttrib("readonly", "readonly");
            $element->setAttrib("size", 7);
            $array_elements[] = $element;
        }
        
        //Total espacios físicos
        foreach($array_tenencia as $keyt => $valuet) {
            $element = new Zend_Form_Element_Text("sumae_{$keyt}");
            $element->helper = "formNote";
            $element->setAttrib("readonly", "readonly");
            $element->setAttrib("size", 7);
            $array_elements[] = $element;
            $element = new Zend_Form_Element_Text("sumam_{$keyt}");
            $element->helper = "formNote";
            $element->setAttrib("readonly", "readonly");
            $element->setAttrib("size", 7);
            $array_elements[] = $element;
        }
        
        $element = new Zend_Form_Element_Text("sumae");
        $element->helper = "formNote";
        $element->setAttrib("readonly", "readonly");
        $element->setAttrib("size", 7);
        $array_elements[] = $element;
        
        $element = new Zend_Form_Element_Text("sumam");
        $element->helper = "formNote";
        $element->setAttrib("readonly", "readonly");
        $element->setAttrib("size", 7);
        $array_elements[] = $element;
        
        //Suma puestos
        $array_puestos = $domConfig->PUESTOS_INSTALACION_FISICA->toArray();
        foreach($array_puestos as $keyi => $valuei) {
            foreach($array_tenencia as $keyt => $valuet) {
                $element = new Zend_Form_Element_Text("cantidad_{$keyi}_{$keyt}");
//                $element->setValue("cantidad_{$keyi}_{$keyt}");
                $element->addFilter('StripTags');
                $element->addFilter('StringTrim');
                $element->addValidator('digits');
                $element->setAttrib("size", 7);
                $array_elements[] = $element;
//                $element = new Zend_Form_Element_Text("area_{$keyi}_{$keyt}");
//                $element->addFilter('StripTags');
//                $element->addFilter('StringTrim');
//                $element->addValidator('digits');
//                $element->setAttrib("size", 7);
//                $array_elements[] = $element;
            }
            $element = new Zend_Form_Element_Text("sumac_{$keyi}");
            $element->helper = "formNote";
            $element->setAttrib("readonly", "readonly");
            $element->setAttrib("size", 7);
            $array_elements[] = $element;
            
//            $element = new Zend_Form_Element_Text("sumaa_{$keyi}");
//            $element->helper = "formNote";
//            $element->setAttrib("readonly", "readonly");
//            $element->setAttrib("size", 7);
//            $array_elements[] = $element;
        }

        //Total puestos
        foreach($array_tenencia as $keyt => $valuet) {
            $element = new Zend_Form_Element_Text("sumape_{$keyt}");
            $element->helper = "formNote";
            $element->setAttrib("readonly", "readonly");
            $element->setAttrib("size", 7);
            $array_elements[] = $element;
//            $element = new Zend_Form_Element_Text("sumapm_{$keyt}");
//            $element->helper = "formNote";
//            $element->setAttrib("readonly", "readonly");
//            $element->setAttrib("size", 7);
//            $array_elements[] = $element;
        }
        $element = new Zend_Form_Element_Text("sumape");
        $element->setAttrib("readonly", "readonly");
        $element->helper = "formNote";
        $element->setAttrib("size", 7);
        $array_elements[] = $element;
        
//        $element = new Zend_Form_Element_Text("sumapm");
//        $element->setAttrib("readonly", "readonly");
//        $element->helper = "formNote";
//        $element->setAttrib("size", 7);
//        $array_elements[] = $element;

        //Promedios puestos
//        foreach($array_tenencia as $keyt => $valuet) {
//            $element = new Zend_Form_Element_Text("cantidad_50_{$keyt}");
//            $element->addFilter('StripTags');
//            $element->addFilter('StringTrim');
//            $element->addValidator('digits');
//            $element->setAttrib("size", 7);
//            $array_elements[] = $element;
//            $element = new Zend_Form_Element_Text("area_50_{$keyt}");
//            $element->addFilter('StripTags');
//            $element->addFilter('StringTrim');
//            $element->addValidator('digits');
//            $element->setAttrib("size", 7);
//            $array_elements[] = $element;
//        }
//
//       $element = new Zend_Form_Element_Text("sumac_50");
//       $element->setAttrib("readonly", "readonly");
//       $element->helper = "formNote";
//       $element->setAttrib("size", 7);
//       $array_elements[] = $element;
//
//       $element = new Zend_Form_Element_Text("sumaa_50");
//       $element->setAttrib("readonly", "readonly");
//       $element->helper = "formNote";
//       $element->setAttrib("size", 7);
//       $array_elements[] = $element;
        
       $submit = new Zend_Form_Element_Submit('btnSubmit');
       $submit->setValue('Guardar');
       $submit->setLabel("Guardar");
       $submit->setAttrib("class", "iceCmdBtn");
       $array_elements[] = $submit;
       
       $this->addElements($array_elements);
       $this->loadViewScriptDecorators();
       //$this->loadTableDecorators();
    
    }

    public function loadViewScriptDecorators() {
        $this->setDecorators(array(
            array(
                'viewScript',
                array(
                    'viewScript'=>'viewscripts/instalaciones_form.phtml'
                )
            )
        ));
    }
}